import threading
from threading import Thread
import time

ticket = 50


def sale_ticket():
    global ticket
    for i in range(100):
        if ticket > 0:
            print(f'{threading.current_thread().name}正在出售第{ticket}张票')
            ticket -= 1
        time.sleep(1)


if __name__ == '__main__':
    for i in range(3):
        t = Thread(target=sale_ticket)
        t.start()

# Lock中的 acquire方法，锁定状态  release方法，非锁定状态，解决多个线程之间的安全问题
